Computes an SHA512 hash
Syntax
Visual Basic (Declaration) | |
---|
Public Overloads Shared Function SHA512( _
ByVal bytes() As Byte _
) As Hash |
Parameters
- bytes
Example
Library/Library.Test/TestIOStreamUtils.cs
C# | Copy Code |
---|
byte[] testData = new byte[ushort.MaxValue];
new Random().NextBytes(testData);
Array.Clear(testData, 0, testData.Length / 2);
Hash compressedHash;
Hash hash = Hash.SHA512(testData);
using (TempFile f = new TempFile())
{
f.WriteAllBytes(testData);
Assert.AreEqual((long)testData.Length, f.Length);
IOStream.Compress(f.TempPath);
Assert.IsTrue(f.Length < testData.Length);
compressedHash = Hash.SHA512(f.Read());
Assert.IsFalse(compressedHash == hash);
IOStream.Decompress(f.TempPath);
Assert.AreEqual((long)testData.Length, f.Length);
Assert.IsTrue(hash == Hash.SHA512(f.Read()));
}
MemoryStream ms = new MemoryStream(testData), gz = new MemoryStream();
IOStream.Compress(ms, gz);
Assert.IsTrue(compressedHash == Hash.SHA512(gz.ToArray()));
ms = new MemoryStream();
gz.Position = 0;
IOStream.Decompress(gz, ms);
Assert.IsTrue(hash == Hash.SHA512(ms.ToArray())); |
VB.NET | Copy Code |
---|
Dim testData As Byte() = New Byte(UShort.MaxValue) {}
New Random().NextBytes(testData)
Array.Clear(testData, 0, testData.Length / 2)
Dim compressedHash As Hash
Dim hash As Hash = Hash.SHA512(testData)
Using f As New TempFile()
f.WriteAllBytes(testData)
Assert.AreEqual(DirectCast(testData.Length, Long), f.Length)
IOStream.Compress(f.TempPath)
Assert.IsTrue(f.Length < testData.Length)
compressedHash = Hash.SHA512(f.Read())
Assert.IsFalse(compressedHash = hash)
IOStream.Decompress(f.TempPath)
Assert.AreEqual(DirectCast(testData.Length, Long), f.Length)
Assert.IsTrue(hash = Hash.SHA512(f.Read()))
End Using
Dim ms As New MemoryStream(testData), gz As New MemoryStream()
IOStream.Compress(ms, gz)
Assert.IsTrue(compressedHash = Hash.SHA512(gz.ToArray()))
ms = New MemoryStream()
gz.Position = 0
IOStream.Decompress(gz, ms)
Assert.IsTrue(hash = Hash.SHA512(ms.ToArray())) |
Requirements
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
See Also